package top.hg.tool.modules.car.user;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import top.hg.tool.modules.car.article.ArticleEntity;
import top.hg.tool.modules.car.constant.RedisKeyConstant;

import java.util.List;

/**
 * @Author: skh
 * @Date: 2019/7/24 16:53
 * @Description:
 */
@Repository
@Slf4j
public class UserRepository {

    @Autowired
    private UserDao userDao;

    public UserEntity getUserByOpenId(String openId) {
        EntityWrapper<UserEntity> wrapper = new EntityWrapper();
        wrapper.eq("open_id", openId);
        List<UserEntity> userEntityList = userDao.selectList(wrapper);
        if (CollUtil.isEmpty(userEntityList)) {
            return null;
        }else {
            return userEntityList.get(0);
        }
    }

    public Integer saveUser(UserEntity userEntity) {
        userDao.insert(userEntity);
        return userEntity.getId();
    }

    public Integer updateUser(UserEntity userEntity) {
        userDao.updateById(userEntity);
        return userEntity.getId();
    }


}
